import './gulpinit';
import { /* series, */ parallel } from 'gulp';
import { run } from './utils/process';
import { withTaskName } from './utils/gulp';
import {
  mainProjectConfig,
  getChildProjectConfig,
  getAllChildName,
  packagePath,
} from './config/index';

// 启动主应用与子应用
export const serveMainChild = () => {
  const result: any[] = [];
  const allChildName = getAllChildName();
  allChildName.forEach((child) => {
    result.push(
      withTaskName(`serveChild:${child}`, () =>
        run(`pnpm run -C ${packagePath}/${child} serve`)
      )
    );
  });

  for (let key in mainProjectConfig) {
    const item = mainProjectConfig[key];
    result.push(
      withTaskName(`serveMain:${key}`, () => run(`pnpm run ${item.serveRun}`))
    );
  }

  return result;
};

export default parallel(...serveMainChild());
